<?php


namespace app\model\user;


use think\Model;
use think\model\concern\SoftDelete;

class UserInvoiceModel extends Model
{
    protected $name = 'user_invoice';
    protected $autoWriteTimestamp = true;

    use SoftDelete;
    protected $defaultSoftDelete = 0;

    protected $json = ['company_type'];
    protected $jsonAssoc = true;

    protected $hidden = ['update_time', 'delete_time'];

    public function user()
    {
        return $this->hasOne(UserModel::class, 'id', 'user_id')->withTrashed()->bind(['username', 'mobile']);
    }

    public function auditor1Name()
    {
        return $this->hasOne(UserModel::class, 'id', 'auditor1')->withTrashed()->bind(['auditor1_name' => 'username']);
    }

    public function auditor2Name()
    {
        return $this->hasOne(UserModel::class, 'id', 'auditor2')->withTrashed()->bind(['auditor2_name' => 'username']);
    }

    public function getAssignTimeAttr($value)
    {
        if (!$value) {
            return '';
        } else {
            return date('Y/m/d H:i', $value);
        }
    }
}